package com.leather.admin.controller;

import com.leather.admin.entity.Permission;
import com.leather.admin.service.AdminService;
import com.leather.admin.vo.AdminVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    @GetMapping("/list")
    @ResponseBody
    public String test() {
        return "hello";
    }

    @RequestMapping("/index")
    public String index(HttpSession session, Model model) {
        AdminVo adminVo = (AdminVo) session.getAttribute("admin");
        List<Permission> permissions = adminService.getAllPermission(adminVo.getAdminName());
        model.addAttribute("permissions", permissions);
        return "index";
    }

}
